from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

db = SQLAlchemy()


# TODO 自定义模型类
# 用户模型类
class User(db.Model):
    uid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment="ID")
    username = db.Column(db.String(32), comment="用户名")
    mobile = db.Column(db.String(11), comment="手机号")
    article = db.relationship("Article", backref="user")


# 文章模型类
class Article(db.Model):
    aid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment="ID")
    title = db.Column(db.String(64), default="", comment="文章内容")
    content = db.Column(db.String(128), default="", comment="文章内容")
    img = db.Column(db.String(256), default="", comment="文章图片")
    bup_time = db.Column(db.DateTime, default=datetime.now(), comment="发表时间")
    user_id = db.Column(db.Integer, db.ForeignKey("user.uid"))
